package com.briup.jz.web.controller;

import com.briup.jz.bean.BaseRolePrivilege;
import com.briup.jz.bean.BaseUserRole;
import com.briup.jz.bean.Category;
import com.briup.jz.service.IBaseUserRoleService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "用户权限")
@RestController
@RequestMapping("/baseUesrRole")
public class BaseUserRoleController {
    @Autowired
    private IBaseUserRoleService baseUserRoleService;

    @PostMapping("/save")
    @ApiOperation("给用户添加角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name="userId",value = "用户Id",paramType = "form", required=true),
            @ApiImplicitParam(name="roleId",value = "角色Id",paramType = "form", required=true),
    })
    public Message save(Long userId,Long roleId){
        BaseUserRole baseUserRole = new BaseUserRole();
        baseUserRole.setRoleId(roleId);
        baseUserRole.setUserId(userId);
        baseUserRoleService.save(baseUserRole);
        return MessageUtil.success("保存成功");
    }

    @ApiOperation(value = "查询用户角色")
    @GetMapping("query")
    public Message query(){
        List<BaseUserRole> list = baseUserRoleService.query();
        return MessageUtil.success(list);
    }

    @GetMapping("/delete")
    @ApiOperation("删除给用户赋予的角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
    })
    public Message delete(Long id){
        baseUserRoleService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

}
